#include "Terrain.h"
#include "ReportError.h"
#include "TextureManager.h"
#include "MeshManager.h"
#include "ObjMesh.h"
#include <assert.h>
Terrain::Terrain()  //: m_triangleSize(8.0f)
{
	m_mat.SetIdentity();
}

bool Terrain::Load(File* f)
{
	//Format will be:
	//Filename for mesh

	if(!f->GetString(&m_meshPath))
	{
		ReportError("TerrainMesh" + __LINE__);
	}
	

	if(!f->GetString(&m_texPath))
	{
		ReportError("terrain tex fail");
	}
	MakeStaticCollisionShapeFromMesh(TheMeshManager::Instance()->GetMesh(m_meshPath), 0, COL_TERRAIN, terrainCollidesWith);
	return true;
	
}

void Terrain::Draw()
{

	assert(mp_motionState);
	glPushMatrix();

		btTransform btTrans;
		mp_motionState->getWorldTransform(btTrans);
		btTrans.getOpenGLMatrix(m_mat.m_matrix);
		m_mat.MultiOpenGL();

	TheTextureManager::Instance()->DrawTexture(m_texPath);
	
	TheMeshManager::Instance()->DrawMesh(m_meshPath);
	
	glPopMatrix();
}

void Terrain::Update()
{
	
}

const char* Terrain::GetTypeName()
{
	return "Terrain";
}



GameObject* TerrainCreate()
{
	return new Terrain;
}

static bool l = TheGameObjectFactory::Instance()->AddToMap("Terrain", TerrainCreate);